<?php

namespace app\common\model\driving;

use think\Model;

/**
 * 围栏计费规则模型
 */
class FreightRule extends Model
{

    

    

    // 表名
    protected $name = 'driving_freight_rule';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'in_exceed_rule_json_text',
        'et_exceed_rule_json_text'
    ];


    public function getInExceedRuleJsonTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['in_exceed_rule_json']) ? $data['in_exceed_rule_json'] : '');
        return $value ? json_decode($value,true) : [];
    }

    public function getEtExceedRuleJsonTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['et_exceed_rule_json']) ? $data['et_exceed_rule_json'] : '');
        return $value ? json_decode($value,true) : [];
    }

    protected static function init()
    {
        self::beforeInsert(function ($row) {
            $changed = $row->getChangedData();
        });

        self::beforeUpdate(function ($row) {
            $changed = $row->getChangedData();
        });

        self::afterInsert(function ($row) {
            $changed = $row->getChangedData();
        });

        self::afterUpdate(function ($row) {
            $changed = $row->getChangedData();
        });
    }

}
